<template>
    <div class="xd-LearningHome-PoliticalNews-NewsHome p_10">
        <el-card class="m_t_b_5px news_panel" shadow="hover">
            <div slot="header">
                <div class="title">校园动态</div>
            </div>
            <ul class="news_list item_flex_ul">
                <li v-for="p in schoolNewsList" :key="p.i_id" @click="goNewsDetail(p.i_id)">
                    <span class="title">· {{decodeURI(p.v_seach_v_notice_title)}}</span>
                    <span class="time">{{p.dtm_publish_date}}</span>
                </li>
                <p v-if="!schoolNewsList.length" class="no-data">{{NO_DATA}}</p>
            </ul>
            <el-pagination
                @size-change="schoolSizeChange"
                @current-change="schoolPageChange"
                :current-page="schoolForm.pageNumber"
                :page-sizes="[10, 20, 30, 40, 50]"
                :page-size="schoolForm.pageSize"
                :layout="PAGE_LAYOUT"
                :total="schoolTotal"
            ></el-pagination>
        </el-card>

        <el-card class="news_panel m_t_15" shadow="hover">
            <div slot="header">
                <div class="title">基层动态</div>
            </div>
            <ul class="news_list item_flex_ul">
                <li v-for="p in jicengNewsList" :key="p.i_id" @click="goNewsDetail(p.i_id)">
                    <span class="title">· {{decodeURI(p.v_seach_v_notice_title)}}</span>
                    <span class="time">{{p.dtm_publish_date}}</span>
                </li>
                <p v-if="!jicengNewsList.length" class="no-data">{{NO_DATA}}</p>
            </ul>
            <el-pagination
                @size-change="jicengSizeChange"
                @current-change="jicengPageChange"
                :current-page="jicengForm.pageNumber"
                :page-sizes="[10, 20, 30, 40, 50]"
                :page-size="jicengForm.pageSize"
                :layout="PAGE_LAYOUT"
                :total="jicengTotal"
            ></el-pagination>
        </el-card>
    </div>
</template>
<script>
export default {
    name: 'NewsHome',
    data() {
        return {
            form: {
                pageNumber: 1,
                pageSize: 10
            },
            total: 0,
            newsList: [],
            schoolNewsList: [],
            schoolForm: {
                pageNumber: 1,
                pageSize: 10
            },
            jicengNewsList: [],
            jicengTotal: 0,
            schoolTotal: 0,
            jicengForm: {
                pageNumber: 1,
                pageSize: 10
            }
        };
    },
    mounted() {
        this.$store.commit('updateActiveMenu', '/LearningHome/PoliticalNews');
        this.fetchSchoolNewsList();
        this.fetchJicengNewsList();
    },
    methods: {
        schoolSizeChange(val) {
            this.schoolForm.pageSize = val;
            this.fetchSchoolNewsList();
        },
        schoolPageChange(val) {
            this.schoolForm.pageNumber = val;
            this.fetchSchoolNewsList();
        },
        jicengSizeChange(val) {
            this.jicengForm.pageSize = val;
            this.fetchJicengNewsList();
        },
        jicengPageChange(val) {
            this.jicengForm.pageNumber = val;
            this.fetchJicengNewsList();
        },
        // sizeChange(val) {
        //   this.form.size = val
        //   this.getNews()
        // },
        // pageChange(val) {
        //   this.form.page = val
        //   this.getNews()
        // },
        goNewsDetail(id) {
            this.$router.push({ path: '/LearningHome/PoliticalNews/NewsDetail', query: { id: id } });
        },
        fetchSchoolNewsList() {
            utils.post('notice/SchoolNewsList', this.schoolForm, res => {
                if (res.success) {
                    this.schoolNewsList = res.data.rows;
                    this.schoolTotal = res.data.total;
                }
            });
        },
        fetchJicengNewsList() {
            utils.post('notice/BasiclevelNewsList', this.jicengForm, res => {
                if (res.success) {
                    this.jicengNewsList = res.data.rows;
                    this.jicengTotal = res.data.total;
                }
            });
        }
    }
};
</script>
<style lang="less">
.xd-LearningHome-PoliticalNews-NewsHome {
    .news_panel {
        ul.news_list li {
            border-bottom: solid 1px #dcdfe6;
            padding-bottom: 5px;
        }
    }
}
</style>